package it.trio.monopoly.domain;

import java.util.ArrayList;
import java.util.List;

public class Board {
	public static final int TOTAL_NUMBER_OF_SQUARES = 40;
	public static final int GO_SQUARE_POSITION = 0;
	public static final int TAX_SQUARE_POSITION = 3;
	public static final int JAIL_SQUARE_POSITION = 9;
    // need to be greater than JAIL_SQUARE_POSITION 
	public static final int GO2JAIL_SQUARE_POSITION = 29;
	
	private List<Square> squares = new ArrayList<Square>();

	public Board() {	
		for(int i = 0; i < TOTAL_NUMBER_OF_SQUARES; i ++)
			if(i==GO_SQUARE_POSITION)
			    squares.add(new GoSquare());
			else if(i==GO2JAIL_SQUARE_POSITION)
			    squares.add(new Go2JailSquare(squares.get(JAIL_SQUARE_POSITION)));
			else if(i==TAX_SQUARE_POSITION)
			    squares.add(new TaxSquare());
			else
			    squares.add(new DoNothingSquare());
	}

	public List<Square> getSquares() {
		return squares;
	}

	public Square getNextSquare(Square square, int diceRollResult) {
		int actualSquarePosition = getSquarePosition(square); 
		int nextSquarePosition = (actualSquarePosition + diceRollResult) % TOTAL_NUMBER_OF_SQUARES;
		Square nextSquare = getSquare(nextSquarePosition);
		return nextSquare;
	}

	public Square getFirstSquare() {
		return squares.get(0);
	}

	// TO DISCUSS public only to be seen by the corresponding test class
	public int getSquarePosition(Square newSq) {
		return squares.indexOf(newSq);
	}

	public Square getSquare(int squarePosition) {
		return squares.get(squarePosition);
	}

}